//
//  RoomGift.m
//  test
//
//  Created by 张征鸿 on 16/11/1.
//  Copyright © 2016年 张征鸿. All rights reserved.
//

#import "RoomGift.h"
#import <Masonry.h>
@implementation RoomGift

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.imgView];
        [self addSubview:self.giftName];
        [self addSubview:self.explainLabel];
        [self masonry];
    }
    return self;
}

- (UIImageView *)imgView
{
    if (!_imgView) {
        _imgView = [[UIImageView alloc] init];
    }
    return _imgView;
}

- (UILabel *)giftName
{
    if (!_giftName) {
        _giftName = [[UILabel alloc] init];
        _giftName.text = @"Iron Man";
    }
    return _giftName;
}

- (UILabel *)explainLabel
{
    if (!_explainLabel) {
        _explainLabel = [[UILabel alloc] init];
        _explainLabel.text = @"ailfjeiwojfiowejifowejiofjewif123jofjoweijiowjfiojwjoiwjfioewjifjwiofjwiofiowej1231312212313213131312313123123231231231232131312313132131231312fhhaha";
        _explainLabel.numberOfLines = 0;
    }
    return _explainLabel;
}

- (void)masonry
{
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(@16);
        make.size.mas_equalTo(CGSizeMake(60, 60));
    }];
    
    [self.giftName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@16);
        make.left.equalTo(self.imgView.mas_right).offset(16);
        make.right.equalTo(@16);
        make.height.equalTo(@12);
    }];
    
    [self.explainLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.giftName.mas_bottom).offset(10);
        make.left.equalTo(self.imgView.mas_right).offset(16);
        make.right.equalTo(@-16);
    }];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self calculateViewHeight];

}

- (void)calculateViewHeight
{
    CGFloat height = self.explainLabel.frame.size.height + self.giftName.frame.size.height + 30;
    if ([self.delegate respondsToSelector:@selector(callBackViewHeight:)]) {
        [self.delegate callBackViewHeight:height];
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
